<?php 

// var_dump(11);
        /*echo "<a href='http://127.0.0.1/wewe/app/".$this->createMobileUrl('main')."'>".$this->createMobileUrl('main')."</a>";*/
        /*echo "<a href='http://127.0.0.1/wewe/app/".$this->createMobileUrl('home')."'>".$this->createMobileUrl('home')."</a><br>";
        echo "<a href='http://127.0.0.1/wewe/web/".$this->createWebUrl('home')."'>".$this->createWebUrl('home')."</a><br>";
        if(load()->func('db')) {
            echo '1';
        }
        $cloudapi = load()->object('cloudapi');
        isset($cloudapi);*/

        /*$data = array(1,2,3);

        cache_write('test',$data);
        cache_write('test1','testdata');
        var_dump('test');*/
        /*$data = array(1,2,3);
        cache_write('test',$data);
        $result = cache_load('test');
        cache_write('test1','testdata');
        cache_load('test1');*/

        /*$cachekey = cache_system_key('permission:%s:%s',$_W['uniacid'],$_W['uid']);
        $cache = cache_load($cachekey);
        var_dump($cache);*/
        /*$sql = "select * from".tablename('users');
        echo $sql;
        echo "<br>";*/
        /*$account = pdo_get('account',array('acid >' => '269'));
        pdo_update('users_failed_login',array('count +=' => 1),array('username' => 'mizhou'));

        pdo_getall('users',array('uid' => array('1','2','3')));
        pdo_fetchall("select * from `ims_users` WHERE `uid` IN (:__uid_0,:__uid_1,:__uid_2)",array(':__uid_0' => 1,':__uid_1' => 2, ':__uid_2' => 3));*/

        /*$usercount = pdo_get('users',array(),array('COUNT(*)','uid','MAX(uid)','MIN(uid) AS minuid'));
        $arr = array (
                 '0' => 103,
                 'uid' => 1,
                 '2' => 179,
                 'minuid' => 1
                );
        var_dump($usercount);*/

        /*$user = pdo_get('users',array('uid' => 1),array('username','uid','salt'));
        var_dump($user);
        $sql = "select username,uid,salt from ims_users where uid = '1'";
        echo $sql;*/

        /*$user = pdo_getall('users',array('status' => 1));
        var_dump($user);*/

        /*$user = pdo_getslice('user',array(),array(0,1),$total);
        var_dump($total);

        $user = pdo_fetch("select username,uid from ".tablename('users')." where uid = '1'");
        var_dump($user);*/

        /*$user_total = pdo_fetchcolumn("select count(*) from ".tablename('userapi_reply'));
        var_dump($user_total);

        $user = pdo_fetchall("select uid,username from ".tablename('users'),array(),'uid');
        var_dump($user);*/

        /*$user_data = array(
            'username' => 'zhao',
            'groupid' => '3'
        );
        $result = pdo_insert('users',$user_data);
        $user = pdo_get('users',array('uid' => 2),array('groupid','username'));
        var_dump($user);

        $user_data = array('username' => 'yalong');
        $result = pdo_update('users',$user_data,array('uid' => 2));
        $user = pdo_getall('users',array('uid' => 2));
        var_dump($user);
        $result1 = pdo_delete('users',array('username'=>'yalong'));
        $arr = array(
            'username' => 'long',
            'groupid' => '5'
        );
        $result = pdo_insert('users',$arr);
        $res = pdo_getall('users',array('uid' => 4));
        var_dump($res);*/
        /*$result = pdo_query("update ".tablename('users')."set username = iloveyou where uid = 4");
        $result2 = pdo_get('users',array('uid' => 4));
        var_dump($result2);*/
        /*$result = pdo_query("delete from ".tablename('users')."where uid = 3");
        isset(pdo_fieldexists('users','status'));*/
        /*pdo_fieldmatch('users','uid','int');
        pdo_debug();*/
        /*$query = load()->object('query');
        $row = $query->from('users','u')->select('u.username')->get();
        var_dump($row);*/
        /*$query = load()->object('query');
        $row = $query->from('users','u')->select('uid','username')->get();
        $row = $query->from('users','u')->select(array('uid','username'))->get();*/
        //var_dump($row);
        /*$query = load()->object('query');
        $row = $query->from('users','u')->where('u.groupid','1')->where('uid >=','2')->get();
        var_dump($row);*/
        /*？？？$query = load()->object('query');
        $rwo = $query->from('users','u')->where(array('u.groupid' => 1,'uid >=' => 2))->get();
        var_dump($row);*///输出boolean false
        /*$query = load()->object('query');
        $row = $query->from('users','u')->where('uid',4)->whereor('groupid',1)->get();
        var_dump($row);*/
        /*$query = load()->object('query');
        $row = $query->from('users','u')->having('count(*) <', 6)->groupby('groupid')->getall();
    
        $query1 = load()->object('query');
        $row1 = $query->from('users','u')->groupby('u.groupid')->get();*/
        /*$query = load()->object('query');
        $row = $query->from('users','u')->orderby('u.uid','asc')->get();
        var_dump($row);
        */
    /*  $query = load()->object('query');
        $row = $query->from('users','u')->leftjoin('userapi_reply','b')->on('u.uid','b.id')->where('u.id',1)->get();
        var_dump($row);*/
        /*$query = load()->object('query');
        $row = $query->from('users','u')->limit(1,1)->getall();
        var_dump($row);*/
        /*$query = load()->object('query');
        $row = $query->from('users','u')->page(1,1)->getall();
        $queryq = load()->object('query');
        $rowq = $query->from('users','u')->limit(1,10)->getall('uid');
        var_dump($rowq);
    */  
        /*$query = load()->object('query');
        $row = $query->from('users','u')->getcolumu('username');
        var_dump($row);*/
        /*$query = load()->object('query');
        $row = $query->from('users','u')->count();
        var_dump($row);*/
        /*$query = load()->object('query');
        $is_found = $query->from('users','u')->where('uid',1)->exists();
        var_dump($is_found);*/
    /*  $pindex = max(1,intval($_GPC['page']));
        $psize = 20;
        $query = load()->object('query');
        $row = $query->from('users','u')->page($pindex,$psize)->getall();
        $total = $query->getLastQueryTotal();
        $pager = pagination($total,$pindex,$psize);
        print_r($query->getLastQuery());*/
        /*{data func="site_navs" item="row"}
        {$row['html']}
        {/data}
        {data func="site_navs" section="1" item="row"}
            第$row['iteration']个:{$row['html']}
        {/data}*/
/*???????var_dump(xml2array('<xml><TagName><![CDATA[A]]></TagName></xml>'));
        array('size'=>1)
        'TagName' => string 'A'(length=1);*/

        /*echo scriptname();
        echo utf8_bytes('264D');
        echo ihtml_entity_decode('<b>title</b><div>con tent"</div>');
        var_dump(iarray_change_key_case(array('ACTION' =>ZS,'TAI'=>FENG),$case = CASE_LOWER));
        var_dump(parse_path('<?php'));
        strip_gpc($values,$type='g');
        */
        /*load()->func('communication');
        $image = 'https://mmbiz.qlogo.cn/mmbiz_jpg/W0GqhYibias7vXCSLoQicrfiaBJ5bT96UKOMpXDibZdCcJFbCjG30h2Sibxn5HtJp7DZAyOydJ2gttaicMlGfZicrd4yrg/0?wx_fmt=jpeg';
        $content = ihttp_request($image,'',array('CURLOPT_REFERER'=>'http://www.qq.com'));
        header('Content-Type:image/jpg');
        echo $content['content'];
        exit();
*/
/*????????? load()->func('communication');
        $response = ihttp_request(ALIPAY_GATEWAY.'?'.http_build_query($set,'','&'),array(),array('CURLOPT_FOLLOWLOCATION'=>0));
        return array('url' => $response['headers']['Location']);*/
    /*  load()->func('communication');
        $loginurl = 'http://mp.weixin.qq.com/cgi-bin/login?lang=zh_CN';
        $post = array(
                    'username' => $username,
                    'pwd' =>$password
                    );
        $response = ihttp_request($loginurl,$post);
        is_error($response) ? return false : return true;*/
/*?????load()->func('communication');
        $url = "https://api.weixin.qq.com/cgi-bin/media/upload?access_token={$token}&type={$type}";
        $data = array(
                    'media' => '@' . ATTACHMENT_ROOT . '/images/2017/03/20/e9e9xhbZsB28HB8bs9bMT228eb85q2bS.jpg',);
        return ihttp_request($url ,$data);*/
        /*load()->func('communication');
        $response = ihttp_get('http://baidu.com');
        print_r($response['content']);*/
/*
        $attachment1 = '@' . ATTACHMENT_ROOT t. '/images/691/2016/08/test1.jpg';
        $attachment2 = '@' . ATTACHMENT_ROOT . '/images/691/2016/08/test2.jpg';
        $content1 = "内容1";
        $content2 = "内容2";
        $body = array(
                    $conten1,
                    $content2,
                    $attachment1,
                    $attachment2
                );
        load()->func('communication');
        $response = ihttp_email('979296092@qq.com','您好，我是赵亚龙',$body);
*/  
        /*load()->func('file');
        file_write('images/201703/23/aa.jpg','图片内容');*/
    /*  load()->func('file');
        file_read('images/201703/23/aa.jpg');
        load()->func('file');
        file_move(IA_ROOT . '/test.log',IA_ROOT . '/web/test.log');
    */  
/*???????   load()->func('file');
        $files = file_tree(IA_ROOT . '/web/common');
        print_r($files);
        array(
            '0' => D:/wamp/www/wewe/web/common/bootstrap.sys.inc.php,
            '1' => D:/wamp/www/wewe/web/common/common.func.php,
            '2' => D:/wamp/www/wewe/web/common/frames.inc.php,
            '3' => D:/wamp/www/wewe/web/common/template.func.php,
            '4' => D:/wamp/www/wewe/web/common/tpl.func.php
            );
        load()->func('file');
        $files = file_tree(IA_ROOT . '/web',array('common','source'));
        print_r($files);*/
        /*load()->func('file');
        file_copy(IA_ROOT . '/web/two',IA_ROOT . '/data/one',array('php'));*/

    /*  load()->func('file');
        file_upload($_FILE['aa'],'image','test.jpg');*/
        /*load()->func('file');
        file_image_thumb(IA_ROOT . '/aa.jpg',IA_ROOT . '/bb.jpg',100);
        file_image_crop(IA_ROOT . '/aa.jpg',IA_ROOT . '/cc.jpg',500,500);*/
/*??????load()->func('file');
        $files = file_lists(IA_ROOT . '/web/common',1,'.php',0,1);
        print_r($files);

        array(
    'web/common/bootstrap.sys.inc.php' => 0fda4e584ef1536a4c7e288b807e0e1b,
    'web/common/common.func.php' => 8f9c8510fea317feed355a25c7802d27,
    'web/common/frames.inc.php' => b4c9ae32c77677279ac35dfebcc92257,
    'web/common/template.func.php' => 8dab868691f0fc9ce325b30d44faf378,
    'web/common/tpl.func.php' => b1a172d3290a4cd3456311fae8cf6196,
            );*/
        /*load()->func('file');
        file_remote_attach_fetch(IA_ROOT . 'dd.jpg');
        load()->func('file');
        mkdirs(IA_ROOT . '/web/three');
        rmdirs(IA_ROOT . '/web/three');*/
    /*???$scahema = db_table_serialize();
        var_dump($scahema);*/
    /*????$table1 = array('tablename' =>        'zefeng',
                        'fields' => 'jingdong');
        $table2 = array('tablename' => 'zefeng',
                        'fields' => 'taobao');
        var_dump(db_schema_compare($table1,$table2));*/
  /*????????$table1 = array('tablename' =>      'zefeng',
                        'fields' => 'jingdong');
        $scahema = _db_build_index_sql(array('$table1' => array('name','age'),'type' => 'index'));
        echo $scahema;*/
        // $scahema = _db_build_sql(array('type' => 'name','default' => 12, 'increment' => 'AUTO_INCREMENT'));
        // echo $scahema;

        // $scahema = db_table_schemas('ims_account');
        // var_dump($scahema);
        // pdo_run("create table `ims_account` (
        //              `acid` int(10) unsigned NOT NULL AUTO_INCREMENT,
        //              `uniacid` int(10) unsigned NOT NULL,
        //              `hash` varchar(8) NOT NULL,
        //              `type` tinyint(3) unsigned NOT NULL,
        //              `isconnect` tinyint(4) NOT NULL,
        //              `isdeleted` tinyint(3) unsigned NOT NULL,
        //              PRIMARY KEY (`acid`),
        //              KEY `idx_uniacid` (`uniacid`)
        //              ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
        //      ");

global $_GPC, $_W;

if($_GPC['et'] == 2) {

    include $this->template('adindex');
    return;
}

if($_GPC['et'] == 3) {

    include $this->template('lastindex');
    return;
}
    

    //保存数据
if($_GPC['et'] == 4) {

    $data = $_POST;
    //var_dump($data['name']);
    //$len = strlen($data['phonenum']);
    
    //echo $len;
   
    $table = new KefuguanliTable();

    $res = $table->addData($_POST);

    if(empty($res)) {
        message('数据不能为空','refresh','error');
    }
    return  message('添加成功', aurl(), 'success');
}
    /*if(!empty($res)) {
        $uid = pdo_insertid();
    return;
}*/
//修改信息
if($_GPC['et'] == 5) {
    // $uid = $_GET['uid'];
    
    // // $table = new KefuguanliTable();
    // $table = model('Kefuguanli');

    // $sql2 = $table->findRow($_GET['uid']);

    // if($sql2 === false) {
    //     message($table->getMessage(), 'referer', 'error');
    // }

    // if(empty($sql2)) {
    //     message('数据不能为空','refresh','error');
    // }

    $sql2 = logic('Kefuguanli')->updateData($_GET['uid']);
    if($sql2 === false) {
        message(logic()->getMessage(),'refresh','error');
    }



    $this->assign('sql2', $sql2);
    $this->display('chindex');

    // $sql2 = pdo_get('szxh_nmyx_activeexpirty_kefuguanli',array('uid'=>$uid));
    
    // include $this->template('chindex');
    return;
}  

//更新数据 
if($_GPC['et'] == 6) {
    $dataone = $_POST;

    $uptable = new KefuguanliTable();
    $result = $uptable->update($_POST);
    if(empty($result)) {
        message('数据为空，不能更新','refresh','error');
    }
    $table = new KefuguanliTable();
    $sql1 = $table->getList($_GET['page']);
    $html = $table->pageHtml();
    include $this->template('index');
    return;
}

//删除数据
if($_GPC['et'] == 7) {
    //$data = $_POST['checkname'];
    //var_dump($data);
    /*if (empty($data)) {
        message('请勾选删除的对象','refresh','error');
    } else{*/
        /*foreach ($data as $value) {
            $del = pdo_delete('szxh_nmyx_activeexpirty_kefuguanli',array('uid'=>$value));
        } */
    //}
    $deltable = new KefuguanliTable();
    $deltable ->delDate($_POST['checkname']);
    $table = new KefuguanliTable();
    $sql1 = $table->getList($_GET['page']);
    $html = $table->pageHtml();
    include $this->template('index');
    return;
} 



$res = logic('Kefuguanli')->tableList($_GET['page']);

if($res === false) {
    message(logic()->getMessage(),'refresh','error');
}

$this->assign('sql1', $res['sql1']);
$this->assign('html', $res['html']);
$this->display('index');

